package com.example.performance.r2dbc.entity;

import io.r2dbc.spi.Readable;

import java.util.function.Function;

/**
 * @author zpMeng
 * @since 6/18/2025
 */
public class RecordRowMapper implements Function<Readable, RecordDb> {
    @Override
    public RecordDb apply(Readable row) {
        return new RecordDb(
                getLong(row, "DS_ID"),
                getLong(row, "NODE_ID"),
                getString(row, "ID_COMMANDE"),
                getString(row, "ID_CLIENT"),
                getDouble(row, "QTE_COMMANDE"),

                getLong(row, "DATE_EXPED_DEMAND"),
                getLong(row, "DATE_DLUO"),
                getLong(row, "DATE_PROD"),
                getDouble(row, "QTE_LIVRE"),
                getLong(row, "DATE_LIVRAISON"),
                getLong(row, "DATE_PROD_INIT"),
                getDouble(row, "QTE_RELIQUAT"),

                getInt(row, "STATUT"),

                getString(row, "text1"),
                getString(row, "text2"),
                getString(row, "text3"),
                getString(row, "text4"),
                getString(row, "text5"),
                getString(row, "text6"),
                getString(row, "text7"),
                getString(row, "text8"),
                getString(row, "text9"),
                getString(row, "text10"),

                getDouble(row, "qty1"),
                getDouble(row, "qty2"),
                getDouble(row, "qty3"),
                getDouble(row, "qty4"),
                getDouble(row, "qty5"),
                getDouble(row, "qty6"),
                getDouble(row, "qty7"),
                getDouble(row, "qty8"),
                getDouble(row, "qty9"),
                getDouble(row, "qty10"),

                getLong(row, "date1"),
                getLong(row, "date2"),
                getLong(row, "date3"),
                getLong(row, "date4"),
                getLong(row, "date5"),
                getLong(row, "date6"),
                getLong(row, "date7"),
                getLong(row, "date8"),
                getLong(row, "date9"),
                getLong(row, "date10"),

                getString(row, "user_modify")
        );
    }

    public static Integer getInt(Readable rs, String columnLabel) {
        return rs.get(columnLabel, Integer.class);
    }

    public static Long getLong(Readable rs, String columnLabel) {
        return rs.get(columnLabel, Long.class);
    }

    public static Double getDouble(Readable rs, String columnLabel) {
        return rs.get(columnLabel, Double.class);
    }

    public static String getString(Readable rs, String columnLabel) {
        return rs.get(columnLabel, String.class);
    }
}
